<?php
/*this include file creates the body
 *  (<option value=".... bit) of a drop down list
*  showing all user tasks
*/
include($_SERVER['DOCUMENT_ROOT']."/f21na/inc_files/utils/dbconnection.php");
//query for all tasks for selected project
$timesheetid = $mysqli->real_escape_string(trim($_GET["timesheetid"]));
$projectid = $mysqli->real_escape_string(trim($_GET["projectid"]));
$query ="SELECT TaskID, Title FROM tasks WHERE TaskID NOT IN (SELECT task FROM timesheet_lines
WHERE Timesheet = {$timesheetid}) AND Deleted != 1 AND Project = '{$projectid}' ORDER BY Title";
$result = $mysqli->query( $query );

//count the number of returned results
$resultCount = $result->num_rows;
echo "<select name=\"tasksddl\" id=\"tasksddl\" style=\"width: 400px\" onchange=\"allowsubmit()\">";
echo "<option value=\"Please select...\">Please select...</option>";
//if there are some results returned create a table showing the results
if( $resultCount > 0){
	while($row = mysqli_fetch_array($result))
	{
		echo "<option value=\"{$row['TaskID']}\">";
		if(strlen($row['Title']) > 40){
			echo substr($row['Title'], 0, 38)."...";
		} else {
			echo $row['Title'];
		}
			
		echo "</option>";
	}

}
echo "</select>";
//tidy up database connection
$mysqli->close();
?>